package secondStage.part4.字符流;

import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;

/**
 * @ClassName: [ZiFuLiu3]
 * @Description: 字符流读数据的2种方法
 * @Author: [黄劲松]
 * @CreateDate: [2021-04-04]
 * @Version: [v1.0]
 */
/*
构造方法:
    InputStreamReader (InputStream in): 创建一个使 用默认字符集的InputStreamReader
读数据的2种承式:
    int read (): 一次读一个字符数据
    int read (char[] cbuf): 一次读一个字符数组数据*/
public class ZiFuLiu3 {
    public static void main(String[] args) throws IOException {
        InputStreamReader isr = new InputStreamReader(new FileInputStream("java.txt"));

        //int read();一次读一个数据
        /*int ch;
        while ((ch=isr.read())!=-1){
            System.out.print((char)ch);
        }*/
        System.out.println('\n'+"-----分界线------");
        char[] chs =new char[10224];
        int len;
        while ((len=isr.read(chs))!=-1){
            System.out.println(new String(chs,0,len));
        }
        isr.close();
    }
}
